#include "Fingerprint-device.h"
#include <unistd.h>

int main(int argc, char const *argv[])
{
    // FingerPrintDevice fingerDev("/dev/ttyUSB0");
    FingerPrintDevice fingerDev("/dev/ttymxc5");
    while (1)
    {
        bool state = fingerDev.isTouchState();
        cout << "touch state :" << state << endl;
        sleep(1);
    }

    bool ok = false;
    printf("-----------1清空指纹库------------\n");
    ok = fingerDev.clearFingerPrintLib();
    if (!ok)
    {
        fprintf(stderr, "清空指纹库失败");
        return -1;
    }

    printf("-----------2创建握手信号------------\n");
    ok = fingerDev.handshake();
    if (!ok)
    {
        fprintf(stderr, "创建握手信号失败");
        return 1;
    }
    sleep(3);

    printf("-----------录入指纹 请输入存储编号------------\n");
    uint16_t pos;
    cin >> pos;
    ok = fingerDev.recordFingerprint(pos);
    cout << "recordFingerprint :" << ok << " pos" << pos << endl;

    sleep(4);

    printf("-----------验证指纹库------------\n");
    pos = 0;
    ok = fingerDev.verfiyFingerPrint(pos);
    cout << "verfiyFingerPrint :" << ok << " pos" << pos << endl;

    return 0;

#if 0
    cout << "handshake ok :" << ok << endl;
    sleep(3);

    int successMakeFreature = 0;
    for (int i = 0; i < 10; i++)
    {
        printf("-----------3探测是否有指纹------------\n");
        ok = fingerDev.detectImage();
        cout << "detect Image ok :" << ok << endl;
        if (ok)
        {
            // 生成特征码 缓冲号
            printf("-----------探测到指纹成功开始生成特征码------------\n");
            ok = fingerDev.makeImageFeature(successMakeFreature + 1);
            if (ok)
            {
                printf("生成特征码成功\n");
                cout << "Image Feature ok :" << ok << endl;
                successMakeFreature++;
            }
            if (successMakeFreature >= 2)
            {
                break;
            }
        }
        sleep(1);
    }

    if (!ok)
    {
        printf("生成特征码失败");
        return -1;
    }

    printf("-----------4生成模版------------\n");
    ok = fingerDev.generateImageTemplate();
    if (!ok)
    {
        fprintf(stderr, "生成模版失败");
        return -1;
    }
    cout << "generate Image Template ok :" << ok << endl;

    printf("-----------5 存储模版------------\n");
    ok = fingerDev.storeImageTemplate(1);
    if (!ok)
    {
        fprintf(stderr, "存储模版 失败");
        return -1;
    }
    cout << "store Image Template  ok :" << ok << " 1 pos" << endl;
#endif
}
